home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CALib / Implementation / UI / CADisplay.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  8.2 KB  |  440 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CADisplay.cpp
  3.  
  4.     Contains:    Display code for CALib
  5.  
  6.     Written by:    Rick Badertscher
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         
  13.         <2>         5/15/95    RB        Adding CA_CATCH
  14.          <1>     5/12/95    RB        Created
  15.          
  16.     To Do:
  17. */
  18.  
  19. #ifndef _CASESSN_
  20. #include "CASessn.h"
  21. #endif
  22.  
  23. #ifndef _CAFRMUTL_
  24. #include "CAFrmUtl.h"
  25. #endif
  26.  
  27. #ifndef _CAERROR_
  28. #include "CAError.h"
  29. #endif
  30.  
  31. #ifndef _CADOCPRIV_
  32. #include "CADocPriv.h"
  33. #endif
  34.  
  35. #ifndef _CAUTIL_
  36. #include "CAUtil.h"
  37. #endif
  38.  
  39. #ifndef SOM_ODFrame_xh
  40. #include <Frame.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODFacet_xh
  44. #include <Facet.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODShape_xh
  48. #include <Shape.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODTransform_xh
  52. #include <Trnsform.xh>
  53. #endif
  54.  
  55. #ifndef _ODUTILS_
  56. #include <ODUtils.h>
  57. #endif
  58.  
  59. #ifndef SOM_ODWindowState_xh
  60. #include <WinStat.xh>
  61. #endif
  62.  
  63. #ifndef _ODMATH_
  64. #include <ODMath.h>
  65. #endif
  66.  
  67. #ifndef _MATRIX_
  68. #include "Matrix.h"
  69. #endif
  70.  
  71. #ifndef SOM_ODWindow_xh
  72. #include <Window.xh>
  73. #endif
  74.  
  75. #ifndef _CADEBUG_
  76. #include "CADebug.h"
  77. #endif
  78.  
  79. #ifndef _TEMPOBJ_
  80. #include <TempObj.h>
  81. #endif
  82.  
  83. #pragma segment CALib
  84.  
  85. //-------------------------------------------------------------------------
  86. //    Variables 
  87. //-------------------------------------------------------------------------
  88.  
  89. const CATransform kCAIdentityMatrix = {{{kODFixed1, 0, 0},
  90.                                        {0, kODFixed1, 0},
  91.                                        {0,  0, kODFract1}}};
  92.  
  93. //-------------------------------------------------------------------------
  94. //    Layout 
  95. //-------------------------------------------------------------------------
  96.  
  97.  
  98.  
  99. //-------------------------------------------------------------------------
  100.  
  101. pascal CAVisFrame
  102. CAGetVisFrame(    CADocumentRef document, CAFrameRef frame )
  103. {
  104.  
  105. #ifdef RUNTIME_DEBUG
  106.     VALIDATE_DOCREF ("CAGetVisFrame", document);
  107.     VALIDATE_FRAMEREF ("CAGetVisFrame", document, frame);
  108. #endif
  109.  
  110.     Environment*    ev = gCASession->GetEV();
  111.     ODFacet*        facet = kODNULL;
  112.  
  113.     CA_TRY
  114.     
  115.         facet = FacetFromFrameRef (document, frame);
  116.     
  117.     CA_CATCH_ALL
  118.     CA_ENDTRY
  119.     
  120.     return (CAVisFrame) facet;
  121.     
  122. }
  123.  
  124.  
  125. //-------------------------------------------------------------------------
  126.  
  127. pascal    CAVisFrame
  128. CAMakeVisFrame(            CADocumentRef    document,
  129.                         CAFrameRef        frame,
  130.                         RgnHandle        clipRgn,
  131.                         CATransform*    xform,
  132.                         GrafPtr            port )
  133. {
  134.     ODUnused(port);
  135.     
  136. #ifdef RUNTIME_DEBUG
  137.     VALIDATE_DOCREF ("CAMakeVisFrame", document);
  138.     VALIDATE_FRAMEREF ("CAMakeVisFrame", document, frame);
  139. #endif
  140.  
  141.     Environment*    ev            = gCASession->GetEV();
  142.     ODFacet*        newFacet    = kODNULL;
  143.     ODShape*        clipShape;
  144.     
  145.     if (FailIfNotVisible(document)) return NULL;
  146.     
  147.     CA_TRY
  148.     
  149.         TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
  150.         THROW_IF_NULL (tempFrame);
  151.  
  152.         if (clipRgn == NULL)
  153.         {
  154.             clipShape = ODCopyAndRelease (ev, tempFrame->AcquireFrameShape(ev, kODNULL));        
  155.         }
  156.         else
  157.         {
  158.             clipShape = tempFrame->CreateShape (ev);
  159.             clipShape->SetQDRegion(ev, clipRgn);
  160.         }
  161.     
  162.         if (tempFrame->IsRoot (ev))
  163.         {
  164.         
  165.             TempODWindow tempWindow = tempFrame->AcquireWindow (ev);
  166.  
  167.             // Set the root frame's shape to the clipping region
  168.             tempFrame->ChangeFrameShape (ev, clipShape, kODNULL);
  169.             ODRelease (ev, clipShape);
  170.  
  171.             // Create window root facet.
  172.             tempWindow->Open(ev);
  173.             tempWindow->Show(ev);
  174.             tempWindow->Select(ev);
  175.         
  176.             newFacet = tempWindow->GetRootFacet (ev);
  177.         
  178.         }
  179.         else
  180.         {
  181.         
  182.             TempODFrame tempRootFrame = tempFrame->AcquireContainingFrame (ev);
  183.             TempODWindow tempWindow = tempRootFrame->AcquireWindow (ev);
  184.         
  185.             TempODTransform tempXform = tempFrame->CreateTransform(ev);
  186.             THROW_IF_NULL (tempXform);
  187.  
  188.             if (xform == NULL)
  189.                 tempXform->Reset (ev);
  190.             else
  191.                 tempXform->SetMatrix (ev, (ODMatrix*) xform);
  192.         
  193.             newFacet = tempWindow->GetRootFacet(ev)->CreateEmbeddedFacet(ev, tempFrame, clipShape,
  194.                                             tempXform, kODNULL, kODNULL, kODNULL, kODFrameInFront);
  195.  
  196.             ODRelease (ev, clipShape);
  197.         
  198.         }
  199.  
  200.     CA_CATCH_ALL
  201.     CA_ENDTRY        
  202.     
  203.     return (CAVisFrame)newFacet;
  204. }
  205.  
  206.  
  207. //-------------------------------------------------------------------------
  208.  
  209. pascal    void
  210. CAAdjustVisFrame( CAVisFrame visFrame, RgnHandle clipRgn, CATransform* xform )
  211. {
  212.     
  213. #ifdef RUNTIME_DEBUG
  214.     VALIDATE_OBJECT ("CAAdjustVisFrame", visFrame);
  215. #endif
  216.  
  217.     Environment*    ev            = gCASession->GetEV();
  218.     ODShape*        clipShape    = kODNULL;
  219.     ODTransform*    transform    = kODNULL;
  220.     ODFacet*        facet        = kODNULL;
  221.  
  222.  
  223.     facet = (ODFacet*) visFrame;
  224.     
  225.     CA_TRY
  226.     
  227.         if (clipRgn)
  228.         {
  229.             clipShape = facet->GetFrame(ev)->CreateShape (ev);
  230.             clipShape->SetQDRegion (ev, clipRgn);
  231.         }
  232.  
  233.         if (xform)
  234.         {
  235.             // By default the external transform is identity
  236.             transform = facet->GetFrame(ev)->CreateTransform(ev);
  237.             THROW_IF_NULL (transform);
  238.             transform->SetMatrix (ev, (ODMatrix*) xform);
  239.         }
  240.     
  241.         facet->ChangeGeometry(ev, clipShape, transform, kODNULL);
  242.         facet->GetFrame(ev)->Invalidate (ev, kODNULL, kODNULL);
  243.         
  244.     CA_CATCH_ALL
  245.     CA_ENDTRY
  246.     
  247.     ODRelease (ev, clipShape);
  248.     ODRelease (ev, transform);
  249.     
  250.     
  251. }
  252.  
  253.  
  254. //-------------------------------------------------------------------------
  255.  
  256. pascal    void        CARemoveVisFrame(        CAVisFrame visFrame )
  257. {
  258.  
  259. #ifdef RUNTIME_DEBUG
  260.     VALIDATE_OBJECT ("CARemoveVisFrame", visFrame);
  261. #endif
  262.  
  263.     Environment*    ev            = gCASession->GetEV();
  264.     ODFacet*        targetFacet    = (ODFacet*) visFrame;
  265.     ODFrame*        frame;
  266.     ODFacet*        facet;
  267.     
  268.     CA_TRY
  269.     
  270.         frame = targetFacet->GetFrame (ev);
  271.  
  272.         if (frame->IsRoot (ev))
  273.             THROW (kCAErrIllegalOperation);
  274.  
  275.         facet = targetFacet->GetContainingFacet(ev);
  276.         facet->RemoveFacet (ev, targetFacet);
  277.         ODDeleteObject (targetFacet);
  278.         
  279.     CA_CATCH_ALL
  280.     CA_ENDTRY
  281.     
  282. }
  283.  
  284. //-------------------------------------------------------------------------
  285.  
  286. pascal Boolean
  287. CAGetSelected( CAVisFrame visFrame)
  288. {
  289.     Environment* ev = gCASession->GetEV();
  290.  
  291.     CA_TRY
  292.  
  293.         return (((ODFacet*)visFrame)->IsSelected(ev));
  294.     
  295.     CA_CATCH_ALL
  296.     CA_ENDTRY
  297.  
  298.     return (false);
  299. }
  300.  
  301. //-------------------------------------------------------------------------
  302.  
  303. pascal void
  304. CASetSelected( CAVisFrame visFrame, Boolean isSelected )
  305. {
  306.  
  307.     Environment*        ev = gCASession->GetEV();
  308.  
  309.     CA_TRY
  310.  
  311.         ((ODFacet*)visFrame)->SetSelected(ev, isSelected);
  312.     
  313.     CA_CATCH_ALL
  314.     CA_ENDTRY
  315.         
  316. }
  317.  
  318. //-------------------------------------------------------------------------
  319.  
  320. pascal CAHighlight
  321. CAGetHighlight( CAVisFrame visFrame)
  322. {
  323.     Environment*    ev = gCASession->GetEV();
  324.     ODHighlight        highlight;
  325.     
  326.     CA_TRY
  327.     
  328.         highlight = ((ODFacet*)visFrame)->GetHighlight(ev);
  329.     
  330.     CA_CATCH_ALL
  331.     CA_ENDTRY
  332.  
  333.     return ((CAHighlight) highlight);
  334.     
  335. }
  336.  
  337. //-------------------------------------------------------------------------
  338.  
  339. pascal void
  340. CASetHighlight( CAVisFrame visFrame, CAHighlight highlight )
  341. {
  342.     Environment* ev = gCASession->GetEV();
  343.     
  344.     CA_TRY
  345.     
  346.         ((ODFacet*)visFrame)->ChangeHighlight(ev,  (ODHighlight) highlight );
  347.     
  348.     CA_CATCH_ALL
  349.     CA_ENDTRY
  350.  
  351. }
  352.  
  353.  
  354.  
  355. //-------------------------------------------------------------------------
  356.  
  357. pascal void    CAGetVisFrameTransform(    CADocumentRef    document,
  358.                                     CAFrameRef        frameRef,
  359.                                     CATransform*    transform)
  360. {
  361.  
  362.     Environment*    ev            = gCASession->GetEV();
  363.     ODFacet*        facet;
  364.     
  365.     CA_TRY
  366.     
  367.         facet = FacetFromFrameRef (document, frameRef);
  368.     
  369.         TempODTransform tempTransform = facet->AcquireExternalTransform (ev, kODNULL);
  370.         THROW_IF_NULL (tempTransform);
  371.     
  372.         tempTransform->GetMatrix(ev, (ODMatrix*) transform);
  373.         
  374.     CA_CATCH_ALL
  375.     CA_ENDTRY
  376.         
  377. }
  378.  
  379.  
  380. //-------------------------------------------------------------------------
  381.  
  382. pascal void    CAMoveTransformBy    (CATransform* transform, Point offset)
  383. {
  384.     
  385.     ODFixed            x, y;
  386.  
  387.     x = offset.h;
  388.     y = offset.v;
  389.     
  390.     CA_TRY
  391.  
  392.         MxMove( (ODMatrix*) transform, kODTranslateXform, x, y );
  393.             
  394.     CA_CATCH_ALL
  395.     CA_ENDTRY
  396.     
  397. }
  398.  
  399. //-------------------------------------------------------------------------
  400.  
  401. pascal void            CAMoveTransformTo    (CATransform* transform, Point origin)
  402. {
  403.  
  404.     Environment*    ev = gCASession->GetEV();
  405.  
  406.     CA_TRY
  407.     
  408.         TempODTransform tempTransform = new ODTransform;
  409.         THROW_IF_NULL(tempTransform);
  410.         tempTransform->InitTransform(ev);
  411.  
  412.         tempTransform->SetQDOffset (ev, &origin);
  413.  
  414.         tempTransform->GetMatrix (ev, (ODMatrix*) transform);
  415.     
  416.     CA_CATCH_ALL
  417.     CA_ENDTRY    
  418.         
  419. }
  420.  
  421.  
  422. //===========================================================================
  423. #pragma mark '    Utility Routines
  424. //===========================================================================
  425.  
  426.  
  427. Boolean FailIfNotVisible (CADocumentRef doc)
  428. {
  429.  
  430.     if ( ((CADocument*)doc)->GetWindow() == NULL)
  431.     {
  432.         SetCAError (kCAErrFrameAccess);
  433.         return true;
  434.     }
  435.     
  436.     return false;
  437.     
  438. }
  439.  
  440.